<?php

class ColaboradorLogic extends LogicModel {

    public function __construct() {
        parent::__construct(new ColaboradorDAO());
    }

    public function listaDeColaboradoresDoSistema($and = null, $orderby = null, $objectCollection = null) {

        $and = ($and !== null) ? " AND $and" : "";
        $where = "ide_colaborador IN (
                SELECT ide_colaborador FROM pessoal.controle WHERE ide_sistema = " . OID_SIS . "
            )" . $and;

        $exception = array();
        $exception['select']['Controle'] = "ide_sistema = " . OID_SIS;
        return $this->listar($where, $orderby, $objectCollection, $exception);
    }

    public function listaDeColaboradoresSemUsuarioOuSemPerfilNoSistema($orderby = null, $objectCollection = null) {

        $where = "ide_colaborador IN (
                    SELECT ide_colaborador FROM pessoal.controle WHERE ide_sistema = " . OID_SIS . "
			AND ide_colaborador NOT IN ( 
                            SELECT ide_colaborador FROM seguranca.usuario 
                                WHERE ide_usuario IN (
                                    SELECT ide_usuario FROM seguranca.usuario__perfil 
                                        WHERE ide_perfil IN (
                                            SELECT ide_perfil FROM seguranca.perfil WHERE ide_sistema = " . OID_SIS . "
                                        )
                                )
                        )
		)";

        $listColaboradores = $this->listar($where, $orderby, $objectCollection);

        if (!$listColaboradores) {
            return null;
        }

        return $listColaboradores;
    }

    public function obterControleColaborador($idColaborador) {
        $objControleLogic = new ControleLogic();
        $objControle = $objControleLogic->obter("ide_colaborador = {$idColaborador} AND ide_sistema = " . OID_SIS);
        return $objControle;
    }

}

?>
